//
//  WSDataReportFilterItem.m
//  microvision
//
//  Created by zhenjingxiong on 2021/3/6.
//  Copyright © 2021 tencent. All rights reserved.
//

#import "WSDataReportFilterItem.h"

CGFloat const kReportDatafilterFontOfSize = 12;

@interface WSDataReportFilterItem ()

@property (nonatomic, assign, readwrite) CGFloat reportDatafilterMaxWidth;

@end

@implementation WSDataReportFilterItem

- (instancetype)initWithFilterKey:(NSString *)filterKey
            withFilterDefaultList:(NSArray<NSString *> *)filterDefaultList {
    self = [super init];
    if (self) {
        self.reportDataFilterKey = filterKey;
        self.reportDatafilterDefaultList = filterDefaultList;
        self.reportDatafilterMaxWidth = [self filterMaxWidth];
    }
    return self;
}

- (CGFloat)filterMaxWidth {
    CGFloat maxWidth = 0;
    for (NSString *defaultValue in self.reportDatafilterDefaultList) {
        UIFont *reportDatafilterFont = [UIFont systemFontOfSize:kReportDatafilterFontOfSize];
        CGSize size = [defaultValue boundingRectWithSize:CGSizeMake(1000, 20)
                                                 options:NSStringDrawingUsesLineFragmentOrigin
                                              attributes:@{NSFontAttributeName:reportDatafilterFont} context:nil].size;
        CGFloat width = size.width + 35;
        if (width > maxWidth) {
            maxWidth = width;
        }
    }
    CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
    if ((maxWidth < 80)) {
        return 80;
    }
    if (maxWidth > UIScreen.mainScreen.bounds.size.width) {
        return screenWidth;
    }
    return maxWidth;
}

@end
